<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Inv_item extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');
	}

	public function index(){

	  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	  $this->load->view($this->session->userdata('formain'));
	  $this->load->view('layouts/footer');
	}
	public function add_form(){
				$groups = $this->inv_item_model->get_inv_groups(); 
				$types 	= $this->inv_item_model->get_inv_types();
				$uom    = $this->inv_item_model->get_uom();

				$this->load->view($this->session->userdata('foradd'),array(
							'uom'			=> $uom,
							'groups'		=> $groups,
							'type'			=> $types,
							'cogs'			=> $this->inv_item_model->get_cogs(),
							'expense'		=> $this->inv_item_model->get_expense(),
							'sales'			=> $this->inv_item_model->get_sales()
					));
	}
	public function edit_form($id){

			$this->load->view($this->session->userdata('foredit'),array(
							'uom'			=> $this->inv_item_model->get_uom(),
							'groups'		=> $this->inv_item_model->get_inv_groups(),
							'type'			=> $this->inv_item_model->get_inv_types(),
							'cogs'			=> $this->inv_item_model->get_cogs(),
							'expense'		=> $this->inv_item_model->get_expense(),
							'sales'			=> $this->inv_item_model->get_sales(),
							'result'		=> $this->inv_item_model->get_item_data($id)

				));
		
	}
	public function view_form($id){
			$this->load->view($this->session->userdata('forview'),array(
							'uom'			=> $this->inv_item_model->get_uom(),
							'groups'		=> $this->inv_item_model->get_inv_groups(),
							'type'			=> $this->inv_item_model->get_inv_types(),
							'cogs'			=> $this->inv_item_model->get_cogs(),
							'expense'		=> $this->inv_item_model->get_expense(),
							'sales'			=> $this->inv_item_model->get_sales(),
							'result'		=> $this->inv_item_model->get_item_data($id)
				));
	}
	public function search_item(){
			$item_number		= $this->input->post('item_number');
	 		$item_desc			= $this->input->post('item_description');
	 		$item_baseUOM		= $this->input->post('base_uom');
			$item_type			= $this->input->post('item_type');
	 		$item_group			= $this->input->post('item_group');
	 		$item_status		= $this->input->post('item_status');

	 		$query = $this->inv_item_model->search_inv_itemDB($item_number,$item_desc,$item_baseUOM,$item_type,$item_group,$item_status);
			if(!empty($query)) {
			echo json_encode($query);
			}else{
				echo json_encode("none");
			}
		}
	public function insert_item(){
		$inv = $this->input->post('inv');	$pur = $this->input->post('pur');
		$set = $this->input->post('set');	$cos = $this->input->post('cos');
		$sel = $this->input->post('sel');	$ena = $this->input->post('ena');

		$data = array(
	 			':p_item_num'			=> $this->input->post('item_number'),
	 			':p_bu_id' 				=> $this->session->userdata('bu_id'),
	 			':p_description' 		=> $this->input->post('item_description'),
	 			':p_base_uom' 			=> $this->input->post('item_uom'),
	 			':p_item_type' 			=> $this->input->post('item_type'),
	 			':p_item_group' 		=> $this->input->post('item_group'),
	 			':p_item_status' 		=> $this->input->post('item_status'),
	 			':p_cogs_acct_id' 		=> $this->input->post('cogs_acct'),
	 			':p_expense_acct_id' 	=> $this->input->post('exp_acct'),
	 			':p_sales_acct_id' 		=> $this->input->post('sales_acct'),
	 			':p_inventory_flag' 	=> ($inv == "ok" ? 'Y' : 'N'),
	 			':p_set_flag' 			=> ($set == "ok" ? 'Y' : 'N'),
	 			':p_sell_flag' 			=> ($sel == "ok" ? 'Y' : 'N'),
	 			':p_purchasing_flag' 	=> ($pur == "ok" ? 'Y' : 'N'),
	 			':p_costing_flag' 		=> ($cos == "ok" ? 'Y' : 'N'),
	 			':p_enable_flag' 		=> ($ena == "ok" ? 'Y' : 'N'),
	 			':p_user_id' 			=> $this->session->userdata('user_id'),
	 			':p_unit_selling_price' => $this->input->post('unit_selling_price')
	 		);

		$this->inv_item_model->insert_item($data);

	}
	public function update_item(){
		$inv = $this->input->post('inv');	$pur = $this->input->post('pur');
		$set = $this->input->post('set');	$cos = $this->input->post('cos');
		$sel = $this->input->post('sel');	$ena = $this->input->post('ena');

		$data = array(
	 			':p_item_num'			=> $this->input->post('item_number'),
	 			':p_bu_id' 				=> $this->session->userdata('bu_id'),
	 			':p_description' 		=> $this->input->post('item_description'),
	 			':p_base_uom' 			=> $this->input->post('item_uom'),
	 			':p_item_type' 			=> $this->input->post('item_type'),
	 			':p_item_group' 		=> $this->input->post('item_group'),
	 			':p_item_status' 		=> $this->input->post('item_status'),
	 			':p_cogs_acct_id' 		=> $this->input->post('cogs_acct'),
	 			':p_expense_acct_id' 	=> $this->input->post('exp_acct'),
	 			':p_sales_acct_id' 		=> $this->input->post('sales_acct'),
	 			':p_inventory_flag' 	=> ($inv == "ok" ? 'Y' : 'N'),
	 			':p_set_flag' 			=> ($set == "ok" ? 'Y' : 'N'),
	 			':p_sell_flag' 			=> ($sel == "ok" ? 'Y' : 'N'),
	 			':p_purchasing_flag' 	=> ($pur == "ok" ? 'Y' : 'N'),
	 			':p_costing_flag' 		=> ($cos == "ok" ? 'Y' : 'N'),
	 			':p_enable_flag' 		=> ($ena == "ok" ? 'Y' : 'N'),
	 			':p_user_id' 			=> $this->session->userdata('user_id'),
	 			':p_item_id'			=> $this->input->post('item_id'),
	 			':p_unit_selling_price' => $this->input->post('unit_selling_price')
	 		);

		$this->inv_item_model->update_item($data);

	}
	 
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */